/**
 * 
 */
package com.hs.auth.dao.impl;

import java.util.List;
import java.util.Map;

import org.hibernate.Query;
import org.springframework.stereotype.Repository;

import com.hs.auth.dao.IUserDao;
import com.hs.auth.model.HsAccount;
import com.hs.core.dao.impl.BaseDao;
import com.hs.core.model.BaseBean;
import com.hs.core.utils.PageParam;
import com.hs.core.utils.PageQuery;
import com.hs.core.utils.PageUtil;

/**
 * @author shl
 *
 * Dec 9, 2010
 */
@Repository 
public class UserDao extends BaseDao implements IUserDao{
	 
	public PageUtil getUserList(PageParam pageParam){
		PageQuery pq = new PageQuery(pageParam);
		Query query = null;
		query = this.getSession().createQuery(pageParam.getSearchSql());
		Map map =pageParam.getConditionMap(); 
		int i = 0;
		if(map.containsKey("prename"))
		{     
			query.setString(i++, "%"+(String)map.get("prename")+"%");
		} 
		if(map.containsKey("precomfrom"))
		{     
			query.setString(i++, "%"+(String)map.get("precomfrom")+"%");
		} 
		PageUtil pu = pq.getPageUtil(query,this.getSession());

		return pu;
	}
	public PageUtil getAccList(PageParam pageParam){
		PageQuery pq = new PageQuery(pageParam);
		Query query = null;
		query = this.getSession().createQuery(pageParam.getSearchSql());
		Map map =pageParam.getConditionMap(); 
		int i = 0;
		if(map.containsKey("userName"))
		{     
			query.setString(i++, "%"+(String)map.get("userName")+"%");
		}  
		PageUtil pu = pq.getPageUtil(query);

		return pu;
	}
	public HsAccount getAccByUid(String uid){ 
		HsAccount obj = null; 
		String hql = "from HsAccount where loginid='" + uid + "' and status=2";
		List accList = this.findList(hql);
		if(null != accList && accList.size() > 0){
			obj = (HsAccount)accList.get(0);
		}
		return obj;
	}
}
